const request = require('request')

function getPage(uri) {
  return new Promise((resolve, reject) => {
    request(uri, (err, res, body) => {
      console.log('-------', 'uri', uri)

      if (err) {
        console.error('api -------', 'error: ', err)
        resolve(0)
      } else if (res.statusCode === 200) {
        resolve(res)
      } else {
        resolve(0)
        console.log('api -------', 'code: ', res.statusCode)
      }
    })
  })
}

module.exports = {
  getPage
}
